package durak.client.view;

import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

public class DurakPanel extends JPanel {

	ImageIcon image;

	public DurakPanel() {
		image = new ImageIcon(getClass().getResource("/durak/resources/images/CardTable.jpg"));
	}

	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		drawTiled(g);
	}

	/*
	 * Custom painting code for drawing a SCALED image as the background
	 */
	private void drawScaled(Graphics g) {
		Dimension d = getSize();
		g.drawImage(image.getImage(), 0, 0, d.width, d.height, null);
	}

	/*
	 * Custom painting code for drawing TILED images as the background
	 */
	private void drawTiled(Graphics g) {
		int width = image.getIconWidth();
		int height = image.getIconHeight();

		for (int x = 0; x < getWidth(); x += width) {
			for (int y = 0; y < getHeight(); y += height) {
				g.drawImage(image.getImage(), x, y, this);
			}
		}
	}

}
